package com.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.api.common.page.PageData;
import com.api.common.service.impl.BaseServiceImpl;
import com.api.entity.ItemInfo;
import com.api.entity.User;
import com.api.entity.dto.UserDTO;
import com.api.mapper.ItemInfoMapper;
import com.api.service.ItemInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 章节表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-30
 */
@Service
public class ItemInfoServiceImpl extends BaseServiceImpl<ItemInfoMapper, ItemInfo> implements ItemInfoService {

    @Override
    public PageData<ItemInfo> page(Map<String, Object> params) {
        IPage<ItemInfo> page = baseDao.selectPage(getPage(params,  false),
                getWrapper(params)
        );
        return getPageData(page, ItemInfo.class);
    }

    private QueryWrapper<ItemInfo> getWrapper(Map<String, Object> params) {
        String name = (String) params.get("name");

        QueryWrapper<ItemInfo> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(name), "name", name);

        return wrapper;
    }


}
